﻿Imports Feed
Imports System
Imports System.IO
Imports System.Net
Imports fmonster.Core
Imports System.Windows
Imports System.Windows.Data
Imports System.Windows.Media
Imports Microsoft.VisualBasic
Imports System.Windows.Controls
Imports System.Windows.Navigation
Imports System.Windows.Media.Animation
Partial Public Class FeedViewPage
    Dim NavComplete As Boolean
    Public Sub New()
        MyBase.New()
        Me.InitializeComponent()
        Dim WBVar As Forms.WebBrowser
        WBVar = CType(BrowserHost.Child, Forms.WebBrowser)
        'AddHandler WBVar.StatusTextChanged, AddressOf StatusTextChanged
        AddHandler WBVar.Navigating, AddressOf BNav
    End Sub
    Public Sub Navigate(ByVal Url As String)
        CType(BrowserHost.Child, Forms.WebBrowser).Navigate(Url)
    End Sub
    Private Sub BNav(ByVal Sender As Object, ByVal E As System.Windows.Forms.WebBrowserNavigatingEventArgs)
        Try
            Dim a1, a, b As String
            a1 = E.Url.ToString
            If a1.StartsWith(Trim("http://")) Then
                E.Cancel = True
                'Global1.CommRoute.ExecuteCommand("NewTabNav", a1)
            End If
            'If a1.Contains("fm://clippings/") = True Then
            '    E.Cancel = True
            '    b = a1.Remove(0, 15)
            '    Dim Item As GenericItems.ItemClasses.GenericItem = [Global].Items.Find(b)
            '    '   If Not IsNothing(Item) Then CL.StoreClip(Item.Link, Item.Title, Item.FeedName)
            'End If
            If a1.Contains("fm://feeds/item/") Then
                E.Cancel = True
                BrowserDocumentText = Feed.Rendering.FeedItems.RenderMultipleItems(a1.Replace("fm://feeds/item/", ""), "Bluepearl")
                Exit Sub
            End If
            Select Case a1
                Case "fm://pagemodel/next"
                    'If Global1.NavComplete = False Then
                    '    Global1.NavComplete = True
                    '    E.Cancel = True
                    '    Dim GenNP As Feed.UI.NewspaperRenderer = New Feed.UI.NewspaperRenderer
                    '    [Global].CurrNPPage = [Global].CurrNPPage + 1
                    '    If [Global].CurrRenderOption = UI.RenderAction.SingleFeedLastest Then
                    '        Global1.CommRoute.ExecuteCommand("RenderNewspaper")
                    '        'CType(BrowserHost.Child, Web.Browser).DocumentText = GenNP.RenderNP(, [Global].CurrRenderOption, [Global].CurrNPPage, Nothing)
                    '    ElseIf [Global].CurrRenderOption = UI.RenderAction.Category Then
                    '        'Global1.CommRoute.ExecuteCommand("RenderNewspaper")
                    '        '   CType(BrowserHost.Child, Web.Browser).DocumentText = GenNP.RenderNP(Nothing, [Global].CurrRenderOption, [Global].CurrNPPage, SelectedCat)
                    '    Else
                    '        CType(BrowserHost.Child, Web.Browser).DocumentText = GenNP.RenderNP(Nothing, [Global].CurrRenderOption, [Global].CurrNPPage, Nothing)
                    '    End If
                    'End If
                Case "fm://pagemodel/prev"
                    'If Global1.NavComplete = False Then
                    '    Global1.NavComplete = True
                    '    E.Cancel = True
                    '    Dim GenNP As Feed.UI.NewspaperRenderer = New Feed.UI.NewspaperRenderer
                    '    [Global].CurrNPPage = [Global].CurrNPPage - 1
                    '    If [Global].CurrRenderOption = UI.RenderAction.SingleFeedLastest Then
                    '        Global1.CommRoute.ExecuteCommand("RenderNewspaper")
                    '    ElseIf [Global].CurrRenderOption = UI.RenderAction.Category Then
                    '        Global1.CommRoute.ExecuteCommand("RenderNewspaper")
                    '    Else
                    '        '   wbContent.DocumentText = GenNP.RenderNP(Nothing, [Global].CurrRenderOption, [Global].CurrNPPage, Nothing)
                    '    End If
                    'End If
                Case "fm://feeds/list"
                    BrowserDocumentText = Feed.Rendering.MakeSubscriptionList.ReturnList(False)
            End Select
        Catch ex As Exception
            '   Global1.DBL.AddItem("BNav: Error " & ex.ToString, FMLogger.Core.DebugLogging.MessageType.UI)
        End Try
    End Sub
    Private Sub StatusTextChanged(ByVal Text As String)
        'Global1.CommRoute.ExecuteCommand("ChangeStatusText", Text)
    End Sub
    Public WriteOnly Property BrowserDocumentText() As String
        Set(ByVal value As String)
            CType(BrowserHost.Child, Forms.WebBrowser).DocumentText = value
        End Set
    End Property
    Public WriteOnly Property BrowserVisibility() As Boolean
        Set(ByVal value As Boolean)
            CType(BrowserHost.Child, Forms.WebBrowser).Visible = value
        End Set
    End Property
    Private Sub Back()
        CType(BrowserHost.Child, Forms.WebBrowser).GoBack()
    End Sub
    Private Sub Forward()
        CType(BrowserHost.Child, Forms.WebBrowser).GoForward()
    End Sub
    Private Sub StopNav()
        CType(BrowserHost.Child, Forms.WebBrowser).Stop()
    End Sub
    Private Sub RefreshNav()
        CType(BrowserHost.Child, Forms.WebBrowser).Refresh()
    End Sub
End Class